<template>
    <div>
        <el-menu :default-active="onRoutes" @open="handleOpen" @close="handleClose" :collapse="isCollapse"
            unique-opened router
            background-color="#324157"text-color="#fff"
            @select="handleSelect"
            active-text-color="#ffd04b">
            <template v-for="item in items">
                <template v-if="item.subs">
                    <el-submenu :index="item.index">
                        <template slot="title">
                            <i :class="item.icon"></i>
                            <span>{{ item.title }}</span>
                        </template>
                        <el-menu-item v-for="(subItem,i) in item.subs" :key="i" :index="subItem.index">
                            {{ subItem.title }}
                        </el-menu-item>
                    </el-submenu>
                </template>
                <template v-else>
                    <el-menu-item :index="item.index">
                        <i :class="item.icon"></i>
                        <span>{{item.title}}</span>
                    </el-menu-item>
                </template>
            </template>
        </el-menu>
    </div>
</template>
<script>
export default {
    
    data(){
        return {
            items: [
                {
                    icon: 'el-icon-setting',
                    index: '/main',
                    title: '首页'
                },
                
                {
                    icon: 'el-icon-tickets',
                    index: '/news',
                    title: '新闻',
                    subs: [
                        {
                            index: '/newsAdd',
                            title: '添加新闻'
                        },
                        {
                            index: '/news',
                            title: '新闻列表'
                        }
                    ]
                },
                {
                    icon: 'el-icon-tickets',
                    index: '/menu',
                    title: '系统管理',
                    subs: [
                        {
                            index: '/menu',
                            title: '权限管理'
                        },
                        {
                            index: '/role',
                            title: '角色管理'
                        }
                    ]
                }
            ]
        }
    },
    computed:{
        onRoutes(){
            //return this.$route.path.replace('/','');
        }
    },
    props: {
        isCollapse: {
            type: Boolean,
            default: false
        }
    },
    methods:{
        handleOpen(){
            console.log('open')
        },
        handleClose(){
            console.log('close')
        },
        handleSelect(index){
            console.log(index)
        }
    }
}
</script>
<style scoped>

.el-menu{
        border-right: solid 0px #e6e6e6;
}
</style>


